package com.zretc.controller;

import java.util.List;

import javax.security.auth.message.callback.PrivateKeyCallback.Request;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import com.zretc.entity.Users;
import com.zretc.service.UsersService;

@Controller
public class UsersController {

	// 控制器要调用的是service
	@Autowired
	private UsersService us;

	@GetMapping(value = "u1")
	// 返回值类型是ModelAndView :
	public ModelAndView getUsersById(int userid) {
		// model就是user
		// view跳转的视图资源
		Users user = us.getUserById(userid);
		// 由于要返回的值是ModelAndView对象
		// 视图资源就是加了前缀: /WEB-INF/jsp/
		// 和后缀 .jsp
		/// WEB-INF/jsp/users.jsp
		ModelAndView mv = new ModelAndView("users");

		// 传递数据
		// request.setAttribute("key", "value");
		mv.addObject("user", user);

		return mv;

	}
	
	@GetMapping(value = "u2")
	// 返回值类型是ModelAndView :
	public ModelAndView getUsers() {
		// model就是user
		// view跳转的视图资源
		List<Users> users = us.getUsers();
		// 由于要返回的值是ModelAndView对象
		// 视图资源就是加了前缀: /WEB-INF/jsp/
		// 和后缀 .jsp
		/// WEB-INF/jsp/users.jsp
		ModelAndView mv = new ModelAndView("userslist");

		// 传递数据
		// request.setAttribute("key", "value");
		mv.addObject("users", users);

		return mv;

	}

}
